package com.ece.devirtualizus.Dao;

import com.ece.devirtualizus.ModelDto.Modules;
import com.ece.devirtualizus.ModelDto.ProgressBarType;

import android.content.ContentValues;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class SqlLiteSessionStoreDao {
	private SQLiteDatabase database;
	private SqlLiteSessionStoreHelper dbHelper;

	public void open() throws SQLException {
		boolean isOk = dbHelper.checkDataBase();
		if (isOk) {
			Log.w("SqlLiteSessionStore.open", "return true");
			this.database = this.dbHelper.getWritableDatabase();
			this.dbHelper.onCreate(this.database);
		} else {
			Log.w("SqlLiteSessionStore.open", "return false");
			this.database = this.dbHelper.getReadableDatabase();
		}
	}

	public void initProgressBarBdd() {

		ContentValues values_module = new ContentValues();

		long rowId_module_pushup = 0;
		long rowId_module_abs = 0;
		long rowId_module_footint = 0;
		long rowId_module_footext = 0;
		long rowId_module_step = 0;
		long rowId_module_weather = 0;
		long rowId_module_depl = 0;

		try {
			/*----------- BEGIN INSERT MODULE TYPE -----------*/
			values_module.put(
					SqlLiteSessionStoreHelper.COLUMN_MODULE_TYPE_LIBELLE,
					Modules.PUSH_UP.toString());
			rowId_module_pushup = this.database.insert(
					SqlLiteSessionStoreHelper.TABLE_MODULE_TYPE, null,
					values_module);

			values_module = null;
			values_module = new ContentValues();
			values_module.put(
					SqlLiteSessionStoreHelper.COLUMN_MODULE_TYPE_LIBELLE,
					Modules.ABS.toString());
			rowId_module_abs = this.database.insert(
					SqlLiteSessionStoreHelper.TABLE_MODULE_TYPE, null,
					values_module);

			values_module = null;
			values_module = new ContentValues();
			values_module.put(
					SqlLiteSessionStoreHelper.COLUMN_MODULE_TYPE_LIBELLE,
					Modules.FOOTING_EXT.toString());
			rowId_module_footext = this.database.insert(
					SqlLiteSessionStoreHelper.TABLE_MODULE_TYPE, null,
					values_module);

			values_module = null;
			values_module = new ContentValues();
			values_module.put(
					SqlLiteSessionStoreHelper.COLUMN_MODULE_TYPE_LIBELLE,
					Modules.FOOTING_INT.toString());
			rowId_module_footint = this.database.insert(
					SqlLiteSessionStoreHelper.TABLE_MODULE_TYPE, null,
					values_module);

			values_module = null;
			values_module = new ContentValues();
			values_module.put(
					SqlLiteSessionStoreHelper.COLUMN_MODULE_TYPE_LIBELLE,
					Modules.STEP_COUNTER.toString());
			rowId_module_step = this.database.insert(
					SqlLiteSessionStoreHelper.TABLE_MODULE_TYPE, null,
					values_module);

			values_module = null;
			values_module = new ContentValues();
			values_module.put(
					SqlLiteSessionStoreHelper.COLUMN_MODULE_TYPE_LIBELLE,
					Modules.WEATHER.toString());
			rowId_module_weather = this.database.insert(
					SqlLiteSessionStoreHelper.TABLE_MODULE_TYPE, null,
					values_module);

			values_module = null;
			values_module = new ContentValues();
			values_module.put(
					SqlLiteSessionStoreHelper.COLUMN_MODULE_TYPE_LIBELLE,
					Modules.GPS.toString());
			rowId_module_depl = this.database.insert(
					SqlLiteSessionStoreHelper.TABLE_MODULE_TYPE, null,
					values_module);
			/*----------- END INSERT MODULE BAR TYPE -----------*/

		} catch (Exception e) {
			Log.e("SqlLiteSessionStore.insert", e.getMessage());
		}
	}
}
